package com.zjm.behavioral.state;

import java.util.Random;

/**
 * 可以抽奖状态
 */
public class CanRaffleState extends State {

    RaffleActivity raffleActivity;

    public CanRaffleState(RaffleActivity raffleActivity) {
        this.raffleActivity = raffleActivity;
    }

    @Override
    public void deductMoney() {
        System.out.println("已经扣取积分了");
    }

    @Override
    public boolean raffle() {
        System.out.println("正在抽奖，请稍等");
        Random random = new Random();
        int num = random.nextInt(10);
        if (num == 0) {
            raffleActivity.setState(raffleActivity.getDispenseState());
            return true;
        }else{
            System.out.println("没有抽中");
            raffleActivity.setState(raffleActivity.getNoRaffleState());
            return false;
        }
    }

    @Override
    public void dispensePrize() {
        System.out.println("没有中奖，不能发放奖品");
    }
}
